package com.sankuai.inf.leaf.server.service;

import com.sankuai.inf.leaf.server.model.common.Result;
import com.sankuai.inf.leaf.server.service.segment.SegmentIDGenImpl;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Service("SegmentService")
public class SegmentService {

    @Resource
    private IDGen idGen;

    public Result getId(String key) {
        return idGen.get(key);
    }

    @PostConstruct
    public void init() {
        idGen.init();
    }

    public SegmentIDGenImpl getIdGen() {
        if (idGen instanceof SegmentIDGenImpl) {
            return (SegmentIDGenImpl) idGen;
        }
        return null;
    }
}
